//
//  FSResponseAction.m
//  FinancialStore
//
//  Created by zhenqiu on 16/7/21.
//  Copyright © 2016年 zhenqiu. All rights reserved.
//

#import "FSResponseAction.h"
#import "NSArray+Extension.h"
#import "NSDictionary+Extension.h"
#import "NotificationCenterManager.h"

@implementation FSResponseAction

+(id)parseReponseData:(id)data withError:(NSError**)error{
    
    if (data) {
        
        
//        NSLog(@"response data = %@",[data description]);
//        NSLog(@"response data = %@",data);
        
        
        NSMutableDictionary * fdata = [NSMutableDictionary dictionaryWithDictionary:data];
        NSInteger code = [[fdata valueForKey:RS_CODE_KEY] integerValue];
        
        if(code != RS_OK){
            
            NSString * error_msg = [fdata valueForKey:RS_MSG_KEY];
            NSDictionary * userinfo = @{NSLocalizedDescriptionKey:error_msg};
            *error = [NSError errorWithDomain:HAODAI_FINANCIAL_STORE_DOMAIN code:code userInfo:userinfo];
            [fdata removeObjectForKey:RS_MSG_KEY];
        }
        
        [fdata removeObjectForKey:RS_POST_KEY];
        [fdata removeObjectForKey:RS_GET_KEY];
        [fdata removeObjectForKey:RS_CODE_KEY];
        
        return fdata;
    }

    return nil;
}

+(id)getReponseError:(id)error{
    
    
    NSError * errorf = error;
//    NSMutableDictionary * userInfo = [NSMutableDictionary dictionaryWithDictionary:[error userInfo]];
//    NSInteger errorCode = [error code];
//    
//    if(errorCode == NSURLErrorTimedOut){
//        
//        [userInfo setValue:NETWORK_TIME_OUT_MSG forKey:NSLocalizedDescriptionKey];
//        errorf = [NSError errorWithDomain:[error domain] code:[error code] userInfo:userInfo];
//        
//    }else if (errorCode == NSURLErrorNotConnectedToInternet){
//        
//        [userInfo setValue:NETWORK_NOT_CONNECTED_MSG forKey:NSLocalizedDescriptionKey];
//        errorf = [NSError errorWithDomain:[error domain] code:[error code] userInfo:userInfo];
//    }else if(errorCode == NSURLErrorCannotDecodeRawData|| errorCode == NSURLErrorBadServerResponse){
//        
//        
//        [userInfo setValue:NETWORK_APP_ERROR forKey:NSLocalizedDescriptionKey];
//        errorf = [NSError errorWithDomain:[error domain] code:[error code] userInfo:userInfo];
//        
//    }else if (errorCode == RS_USER_AUTH_FAILED){
//        
//        [userInfo setValue:@"" forKey:NSLocalizedDescriptionKey];
//        errorf = [NSError errorWithDomain:[error domain] code:[error code] userInfo:userInfo];
//        [NotificationCenterManager sendNotification:USER_AUTH_FAILED_NOTIFICATION withUserInfo:[error userInfo]];
//        
//    }else{
//        
//    }
//    
    return errorf;
}



@end
